<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="评测标题" prop="evalutionName">
        <el-input
          v-model="queryParams.evalutionName"
          placeholder="请输入评测标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="topicTaskList" >
      <el-table-column label="评测标题" prop="evalutionName" width="180" :show-overflow-tooltip="true" />
      <el-table-column label="实验中心" prop="orgName" width="180" :show-overflow-tooltip="true" />
      <el-table-column label="校评状态" align="center" prop="statusName" />
      <el-table-column label="提交时间" align="center" prop="submitTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实验室利用率" align="center" prop="labUsingScore" width="100"/>
      <el-table-column label="设备利用率" align="center" prop="devicesUsingScore" width="100"/>
      <el-table-column label="大型设备利用率" align="center" prop="bigDeviceScore" width="100"/>
      <el-table-column label="实验室运行" align="center" prop="labRuningScore" width="100"/>
      <el-table-column label="资料上报" align="center" prop="dataReportScore" width="100"/>
      <el-table-column label="团队建设" align="center" prop="teamBuildScore" width="100"/>
      <el-table-column label="实验室安全" align="center" prop="securityScore" width="100"/>
      <el-table-column label="信息化建设" align="center" prop="informationScore" width="100"/>
      <el-table-column label="教学" align="center" prop="teachingScore" width="100"/>
      <el-table-column label="开放项目" align="center" prop="openProjectScore" width="100"/>
      <el-table-column label="队伍建设成果" align="center" prop="teamResultScore" width="100"/>
      <el-table-column label="校企共建" align="center" prop="schoolEnterpriseScore" width="100"/>
      <el-table-column label="教学资源" align="center" prop="teachingResourceScore" width="100"/>
      <el-table-column label="对外交流" align="center" prop="foreignExchangesScore" width="100"/>
      <el-table-column label="操作" align="center" fixed="right"  width="100">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['evalution:topicTask:edit']"
          >打分</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改评测人员对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>

      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-form-item label="实验中心" prop="orgName">
            <el-input v-model="form.orgName" placeholder="请输入实验中心名称" disabled style="width: 530px;"/>
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="9">
          <el-form-item label="实验室利用率" prop="labUsingScore">
            <el-input v-model="form.labUsingScore" placeholder="请输入实验室利用率得分"  type="number" :min="0" :max="12" />
          </el-form-item>
          </el-col>
          <el-col :span="2"><span class="selfMark">自评:{{form.parent.labUsingScore}}</span></el-col>
          <el-col :span="9">
          <el-form-item label="设备利用率" prop="devicesUsingScore">
            <el-input v-model="form.devicesUsingScore" placeholder="请输入设备利用率得分" type="number" :min="0" :max="10"/>
          </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.devicesUsingScore}}</span></el-col>
        </el-row>
        <el-row>
          <el-col :span="9">
        <el-form-item label="大型设备利用率" prop="bigDeviceScore">
          <el-input v-model="form.bigDeviceScore" placeholder="请输入大型设备利用率得分" type="number" :min="0" :max="8"/>
        </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.bigDeviceScore}}</span></el-col>
        <el-col :span="9">
        <el-form-item label="实验室运行" prop="labRuningScore">
          <el-input v-model="form.labRuningScore" placeholder="请输入实验室运行得分" type="number" :min="0" :max="4"/>
        </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.labRuningScore}}</span></el-col>
        </el-row>
        <el-row>
          <el-col :span="9">
        <el-form-item label="资料上报" prop="dataReportScore">
          <el-input v-model="form.dataReportScore" placeholder="请输入资料上报得分" type="number" :min="0" :max="3"/>
        </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.dataReportScore}}</span></el-col>
        <el-col :span="9">
        <el-form-item label="团队建设" prop="teamBuildScore">
          <el-input v-model="form.teamBuildScore" placeholder="请输入团队建设得分" type="number" :min="0" :max="3"/>
        </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.teamBuildScore}}</span></el-col>
        </el-row>
        <el-row>
          <el-col :span="9">
        <el-form-item label="实验室安全管理" prop="securityScore">
          <el-input v-model="form.securityScore" placeholder="请输入安全管理得分" type="number" :min="0" :max="20"/>
        </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.securityScore}}</span></el-col>
        <el-col :span="9">
        <el-form-item label="信息化建设" prop="informationScore">
          <el-input v-model="form.informationScore" placeholder="请输入信息化建设得分" type="number" :min="0" :max="10"/>
        </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.informationScore}}</span></el-col>
        </el-row>
        <el-row>
          <el-col :span="9">
        <el-form-item label="教学得分" prop="teachingScore">
          <el-input v-model="form.teachingScore" placeholder="请输入教学得分" type="number" :min="0" :max="20"/>
        </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.teachingScore}}</span></el-col>
        <el-col :span="9">
        <el-form-item label="开放项目" prop="openProjectScore">
          <el-input v-model="form.openProjectScore" placeholder="请输入开放项目得分" type="number" :min="0" :max="10"/>
        </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.openProjectScore}}</span></el-col>
        </el-row>
        <el-row>
          <el-col :span="9">
        <el-form-item label="队伍建设成果" prop="teamResultScore">
          <el-input v-model="form.teamResultScore" placeholder="请输入队伍建设成果得分" type="number" :min="0" :max="8"/>
        </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.teamResultScore}}</span></el-col>
        <el-col :span="9">
        <el-form-item label="校企共建" prop="schoolEnterpriseScore">
          <el-input v-model="form.schoolEnterpriseScore" placeholder="请输入校企共建得分" type="number" :min="0" :max="2"/>
        </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.schoolEnterpriseScore}}</span></el-col>
        </el-row>
        <el-row>
          <el-col :span="9">
        <el-form-item label="教学资源" prop="teachingResourceScore">
          <el-input v-model="form.teachingResourceScore" placeholder="请输入教学资源得分" type="number" :min="0" :max="8"/>
        </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.teachingResourceScore}}</span></el-col>
        <el-col :span="9">
        <el-form-item label="对外交流" prop="foreignExchangesScore">
          <el-input v-model="form.foreignExchangesScore" placeholder="请输入对外交流得分" type="number" :min="0" :max="2"/>
        </el-form-item>
        </el-col>
        <el-col :span="2"><span class="selfMark">自评:{{form.parent.foreignExchangesScore}}</span></el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <TopicDetails ref="detail"></TopicDetails>
  </div>
</template>

<script>
import { listTopicResult, getTopicTask, delTopicTask, addTopicTask, updateTopicTask, exportTopicTask } from "@/api/evalution/topicTask";
import TopicDetails from "@/views/evalution/topic/details"
export default {
  name: "TopicResult",
    components: {TopicDetails},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 评测人员表格数据
      topicTaskList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 打分类型字典
      scoreTypeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        instanceId: null,
        userName: null,
        nickName: null,
        orgId: null,
        orgName: null,
        status: null,
        scoreType: null
      },
      // 表单参数
      form: {
        parent:{},
      },
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "用户工号不能为空", trigger: "blur" }
        ],
       labUsingScore: [
         { type:"number", min:0,max:12, message: "评分限制在0到12之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       devicesUsingScore: [
         { type:"number", min:0,max:10, message: "评分限制在0到10之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       bigDeviceScore: [
         { type:"number", min:0,max:8, message: "评分限制在0到8之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       labRuningScore: [
         { type:"number", min:0,max:4, message: "评分限制在0到4之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       dataReportScore: [
         { type:"number", min:0,max:3, message: "评分限制在0到3之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       teamBuildScore: [
         { type:"number", min:0,max:3, message: "评分限制在0到3之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       securityScore: [
         { type:"number", min:0,max:20, message: "评分限制在0到20之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       informationScore: [
         { type:"number", min:0,max:10, message: "评分限制在0到10之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       teachingScore: [
         { type:"number", min:0,max:20, message: "评分限制在0到20之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       openProjectScore: [
         { type:"number", min:0,max:10, message: "评分限制在0到10之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       teamResultScore: [
         { type:"number", min:0,max:8, message: "评分限制在0到8之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       schoolEnterpriseScore: [
         { type:"number", min:0,max:2, message: "评分限制在0到2之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       teachingResourceScore: [
         { type:"number", min:0,max:8, message: "评分限制在0到8之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
       foreignExchangesScore: [
         { type:"number", min:0,max:2, message: "评分限制在0到2之间", trigger: "blur"
         ,transform: value =>this.$options.filters.formValidateFun(value, "number") }
       ],
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("scoreTypeOpt").then(response => {
      this.scoreTypeOptions = response.data;
    });
  },
  methods: {
    /** 查询评测人员列表 */
    getList() {
      this.loading = true;
      listTopicResult(this.queryParams).then(response => {
        this.topicTaskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 打分类型字典翻译
    scoreTypeFormat(row, column) {
      return this.selectDictLabel(this.scoreTypeOptions, row.scoreType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        evalutionTaskId: null,
        instanceId: null,
        userName: null,
        nickName: null,
        orgId: null,
        orgName: null,
        status: 0,
        submitTime: null,
        labUsingScore: null,
        devicesUsingScore: null,
        bigDeviceScore: null,
        labRuningScore: null,
        dataReportScore: null,
        teamBuildScore: null,
        securityScore: null,
        informationScore: null,
        teachingScore: null,
        openProjectScore: null,
        teamResultScore: null,
        schoolEnterpriseScore: null,
        teachingResourceScore: null,
        foreignExchangesScore: null,
        scoreType: null,
        parent:{},
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.evalutionTaskId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleDetail(row){
      this.$refs["detail"].handleUpdate(row);
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加评测人员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const evalutionTaskId = row.evalutionTaskId || this.ids
      getTopicTask(evalutionTaskId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "实验中心校评";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.evalutionTaskId != null) {
            updateTopicTask(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTopicTask(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const evalutionTaskIds = row.evalutionTaskId || this.ids;
      this.$confirm('是否确认删除评测人员编号为"' + evalutionTaskIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTopicTask(evalutionTaskIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有评测人员数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportTopicTask(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
<style lang="scss" scoped>
  .selfMark{
    font-weight: 400;font-size: 14px;line-height: 36px;
    margin-left: 5px;
  }
</style>
